package org.chandler.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class SqlUtil {
	/*
	 * 获得数据库连接
	 */
	public static Connection GetConn(){
		Connection conn = null;
		String url = "jdbc:mysql://localhost:3306/zxbserver?"
                + "user=root&password=&useUnicode=true&characterEncoding=UTF8";
		try{
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection(url);
			System.out.println("MySQL驱动加载完毕");
		} catch (SQLException e) {
            System.out.println("MySQL操作错误");
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
		return conn;
	}
	/*
	 * 关闭数据库连接
	 */
	public static void CloseConn(Connection conn){
		try {
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
}
